package com.bawei.erp.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.bawei.erp.mapper.SOrderMapper;
import com.bawei.erp.model.SOrder;
import com.bawei.erp.model.Stock;
import com.bawei.erp.service.SOrderService;
import com.bawei.erp.service.StockService;

@Service
public class SOrderServiceImpl implements SOrderService {

	@Resource
	private SOrderMapper sOrderMapper;

	@Resource
	private StockService stockService;

	@Override
	public void addSOrder(SOrder order) {
		sOrderMapper.insert(order);
		stockService.lockStock(order.getSku(), order.getGoodsCount());
	}

	@Override
	public void updateSOrder(SOrder order) {
		sOrderMapper.updateByPrimaryKeySelective(order);
	}

	@Override
	public void deleteSOrder(Long id) {
		sOrderMapper.deleteByPrimaryKey(id);
	}

	@Override
	public List<SOrder> getSOrder() {
		return sOrderMapper.selectByExample(null);
	}

	@Override
	public SOrder getSOrderById(Long id) {
		return sOrderMapper.selectByPrimaryKey(id);
	}

	@Override
	public void lockStock(String sku, int count) {
		Stock stock = new Stock();
		stock.setLockCount(count);
		stock.setSku(sku);
		stockService.updateStockBySKU(stock);
	}
}
